Option Explicit 
Dim xmlDoc,objFSO,objChordFile,objFileName,objInDir
Dim strLyrics,strLine,strChord
Dim strInDirectory,strFullPath
Dim arrLines,arrC
Dim iCnt,i
Dim dicChords,keyChords

set dicChords = CreateObject("Scripting.Dictionary")
'ForAppending = 8 ForReading = 1, ForWriting = 2
Const OpenMode = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set xmlDoc=CreateObject("Microsoft.XMLDOM")

strInDirectory = "Songs"
set objInDir = objFSO.GetFolder(strInDirectory)

'Create file 
Set objChordFile = objFSO.OpenTextFile("chords.csv" , OpenMode, True)
iCnt = 0
For each objFileName in objInDir.Files
	strFullPath = strInDirectory & "\" & objFileName.name

	'Set XML parms
	xmlDoc.async="false"
	xmlDoc.load(strFullPath)

	'Get Elements
	strLyrics = xmlDoc.GetElementsByTagName("lyrics").item(0).text

	'Split the Lyrics into lines
	arrLines = Split(strLyrics,vbLf)

	'Step through the lines
	
	for each strLine in arrLines
		if left(strLine,1) = "." then 
			arrC = split(right(strLine,len(strLine)-1))
			for each strChord in arrC
			        if dicChords.exists(strChord) then 
			        	'
			        else 
			        	dicChords.add strChord," "
			        end If
				'objChordFile.WriteLine(strChord)
				iCnt = iCnt + 1 
			next
		End If 
	Next 
Next

keyChords = dicChords.keys
for i = 0 to  dicChords.count -1 
	objChordFile.WriteLine(keyChords(i))
next 
	
objChordFile.Close

wscript.echo "Completed creating chords " & iCnt
